<template>
  <div class="app-container">
    <!-- <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="负责人" prop="name">
        <el-select v-model="queryParams.name"  placeholder="请选择" clearable @keyup.enter.native="handleQuery">
          <el-option v-for="item in userList" :key="item.userId" :label="item.nickName" :value="item.userName">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="会议主题" prop="confTitle">
        <el-input v-model="queryParams.confTitle" placeholder="请输入会议主题" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="任务状态" prop="taskStat">
        <el-select v-model="queryParams.taskStat"  clearable @keyup.enter.native="handleQuery">
          <el-option
            v-for="dict in dict.type.task_state"
            :key="dict.value"
            :label="dict.label"
            :value="String(dict.value)"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="会议时间" prop="confDate">
        <el-date-picker clearable v-model="queryParams.confDate" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择会议时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="任务反馈批复" prop="feedbackStat">
        <el-select v-model="queryParams.feedbackStat"  clearable @keyup.enter.native="handleQuery">
          <el-option
            v-for="dict in dict.type.sp_sel"
            :key="dict.value"
            :label="dict.label"
            :value="String(dict.value)"
          />
        </el-select>    
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form> -->

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:conference:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['system:conference:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:conference:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:conference:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->

    <el-table v-loading="loading" :data="conferenceList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="id" align="center" prop="id" /> -->
      <el-table-column type="index" width="55" align="center" label="序号" />
      <el-table-column label="会议时间" align="center" prop="confDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.confDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会议主题" align="center" prop="confTitle" />
      <el-table-column label="会议内容" align="center" prop="confContent" />
      <!-- <el-table-column label="负责人" align="center" prop="name" />    -->
      <el-table-column label="负责人" align="center" prop="nickName" />  
      <el-table-column label="抄送人" align="center" prop="ccName" />
      <el-table-column label="任务状态" align="center" prop="taskStat">
        <template slot-scope="scope">
          <el-tag :type="scope.row.taskStat === '0' ?'warning':'success'">
            <dict-tag :options="dict.type.task_state" :value="scope.row.taskStat" />
          </el-tag>  
        </template>
      </el-table-column>
     
      <el-table-column label="任务反馈" align="center" prop="feedback" />
      <el-table-column label="文件名" align="center" prop="filePath" >
        <template slot-scope="scope">
          <el-link :href="baseURL + scope.row.filePath" target="_blank" show-overflow-tooltip>{{
              scope.row.fileName }}</el-link>
          <!-- <a>{{baseURL+ scope.row.filePath }}</a> -->
        </template>
      </el-table-column>
      <el-table-column label="任务反馈批复" align="center" prop="feedbackStat">
        <template slot-scope="scope">
          <el-tag :type="tagTypeChange(scope.row.feedbackStat)">
            <dict-tag :options="dict.type.sp_sel" :value="scope.row.feedbackStat" />
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:conference:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['system:conference:remove']">删除</el-button>
          <el-button  size="mini" type="text" icon="el-icon-s-check"
            @click="handlesp(scope.row)" v-hasPermi="['system:conference:remove']">审批</el-button>
        </template>
      </el-table-column> -->
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改龙翔会议对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="会议主题" prop="confTitle">
          <el-input v-model="form.confTitle" placeholder="请输入会议主题" />
        </el-form-item>
        <el-form-item label="负责人" prop="name">
          <el-select v-model="form.name" placeholder="请选择" @change="setNickName">
            <el-option v-for="item in userList" :key="item.userId" :label="item.nickName" :value="item.userName">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="会议内容" prop="confContent">
          <el-input type="textarea" autosize v-model="form.confContent" :min-height="192" />
        </el-form-item>
        <!-- <el-form-item label="任务状态" prop="taskStat">
          <el-input v-model="form.taskStat" placeholder="请输入任务状态" />
        </el-form-item> -->
        <el-form-item label="会议时间" prop="confDate">
          <el-date-picker clearable v-model="form.confDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择会议时间">
          </el-date-picker>
        </el-form-item>
        
        <el-form-item label="抄送人" prop="ccName">
          <el-select v-model="form.ccName" multiple placeholder="请选择" >
            <el-option v-for="item in userList" :key="item.userId" :label="item.nickName" :value="item.nickName">
            </el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="任务反馈" prop="feedback">
          <el-input v-model="form.feedback" placeholder="请输入任务反馈" />
        </el-form-item> -->
        <!-- <el-form-item label="删除标记，0未删除，1已删除" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标记，0未删除，1已删除" />
        </el-form-item> -->

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 批复任务弹窗 -->
    <el-dialog :title="title" :visible.sync="sp" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="任务反馈批复" prop="feedbackStat">
          <el-radio-group v-model="form.feedbackStat">
            <el-radio v-for="dict in dict.type.sp_sel" :key="dict.value" :label="dict.value">{{ dict.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listConference, getConference, delConference, addConference, updateConference } from "@/api/system/conference";
import { listUser } from '@/api/system/user.js'
export default {
  
  dicts: ['sp_sel', 'task_state'],
  name: "Conference",
  data() {
    return {
      baseURL :process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 龙翔会议表格数据
      conferenceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        confTitle: null,
        confContent: null,
        taskStat: null,
        confDate: null,
        feedback: null,
        feedbackStat: null,
        remark: null,
        fileName: null,
        filePath: null,
        ccName:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "负责人不能为空", trigger: "blur" }
        ],
        confTitle: [
          { required: true, message: "会议主题不能为空", trigger: "blur" }
        ],
        confContent: [
          { required: true, message: "会议内容不能为空", trigger: "blur" }
        ],
        taskStat: [
          { required: true, message: "任务状态不能为空", trigger: "blur" }
        ],
        confDate: [
          { required: true, message: "会议时间不能为空", trigger: "blur" }
        ],
        feedback: [
          { required: true, message: "任务反馈不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ],
        delFlag: [
          { required: true, message: "删除标记，0未删除，1已删除不能为空", trigger: "blur" }
        ],
        feedbackStat: [
          { required: true, message: "任务反馈批复不能为空", trigger: "blur" }
        ],
        createBy: [
          { required: true, message: "创建者不能为空", trigger: "blur" }
        ],
        updateBy: [
          { required: true, message: "更新者不能为空", trigger: "blur" }
        ],
        // remark: [
        //   { required: true, message: "备注不能为空", trigger: "blur" }
        // ]
      },
      // 用户列表数组
      userList: [],
      // 审批弹框
      sp: false,

    };
  },
  created() {
    this.getList();
    // this.getUserList()
  },
  methods: {
       // 审批的色块控制
       tagTypeChange (status) {
      if (status==='1') {
        return "success";
      } else if (status==='2') {
        return "danger";
      } else if (status==='3') {
        return "primary";
      }else{
        return "danger";
      }
},
    // 查询用户列表
    getUserList() {
      listUser().then(res => {
        this.userList = res.rows
      })
    },
    /** 查询龙翔会议列表 */
    getList() {
      console.log(this.$store.state.user);
      const nickName = this.$store.state.user.nickname
      const userName = this.$store.state.user.name
      if (userName !== 'admin') {
        // console.log('不是admin账号');
        this.queryParams.ccName=nickName
      }
      console.log(this.queryParams);
      this.loading = true;
      listConference(this.queryParams).then(response => {
        console.log(response);
        this.conferenceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.sp = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        confTitle: null,
        confContent: null,
        taskStat: null,
        confDate: null,
        feedback: null,
        createTime: null,
        updateTime: null,
        delFlag: null,
        feedbackStat: null,
        createBy: null,
        updateBy: null,
        remark: null,
        fileName: null,
        filePath: null,
        ccName: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    // 选择责任人时，给nickname赋值中文名
    setNickName(e) {
      console.log(e)
      listUser({ userName: e }).then(res => {
        this.form.nickName=res.rows[0].nickName
      })
    },
    
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加龙翔会议";
      // 新增时默认当天
      this.form.confDate = new Date()
      // 新增时默认未读
      this.form.taskStat = 0
      // 新增时默认未审批
      this.form.feedbackStat = 4
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getConference(id).then(response => {
        this.form = response.data;
        if (this.form.ccName) {
          this.form.ccName=this.form.ccName.split(',')
        }
        
        this.open = true;
        this.title = "修改龙翔会议";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        console.log(valid);
        if (valid) {
          if (this.form.ccName) {
            this.form.ccName=this.form.ccName.toString()
            console.log( this.form.ccName);
          }
          console.log(this.form);
          if (this.form.id != null) {
            updateConference(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.sp = false;
              this.getList();
            });
          } else {
            addConference(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;

              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除龙翔会议编号为"' + ids + '"的数据项？').then(function () {
        return delConference(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    // 审批按钮操作
    handlesp(row) {
      this.reset();
      const id = row.id || this.ids
      getConference(id).then(response => {
        this.form = response.data;
        this.sp = true;
        this.title = "审批任务";
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/conference/export', {
        ...this.queryParams
      }, `conference_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
